Conditions | 7 |
Total Lines | 43 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 7 |
Changes | 0 |
1 | /* eslint-env node */ |
||
28 | function gulpWPpot (options) { |
||
29 | 5 | if (options !== undefined && !isObject(options)) { |
|
30 | 1 | throw new PluginError('gulp-wp-pot', 'Require a argument of type object.'); |
|
31 | } |
||
32 | |||
33 | 4 | const files = []; |
|
34 | |||
35 | 4 | const transformer = new Transform({ |
|
36 | objectMode: true, |
||
37 | transform (file, encoding, done) { |
||
38 | 5 | if (file.isStream()) { |
|
39 | 1 | done('error', new PluginError('gulp-wp-pot', 'Streams are not supported.')); |
|
40 | 1 | return; |
|
41 | } |
||
42 | |||
43 | 4 | files.push(file.path); |
|
44 | 4 | done(); |
|
45 | }, |
||
46 | flush (done) { |
||
47 | 3 | if (!options) { |
|
48 | 2 | options = {}; |
|
49 | } |
||
50 | |||
51 | 3 | options.src = files; |
|
52 | 3 | options.writeFile = false; |
|
53 | |||
54 | 3 | try { |
|
55 | 3 | const potContents = wpPot(options); |
|
56 | 2 | const potFile = new Vinyl({ |
|
57 | contents: Buffer.from(potContents), |
||
58 | path: '.' |
||
59 | }); |
||
60 | |||
61 | 2 | this.push(potFile); |
|
62 | 2 | done(); |
|
63 | } catch (error) { |
||
64 | 1 | done('error', new PluginError('gulp-wp-pot', error)); |
|
65 | } |
||
66 | } |
||
67 | }); |
||
68 | |||
69 | 4 | return transformer; |
|
70 | } |
||
71 | |||
73 |